# Definition for an interval.
# class Interval:
#     def __init__(self, s=0, e=0):
#         self.start = s
#         self.end = e

# ab = [[1, 3], [2, 6], [8, 10], [15, 18]]
# a = [1, 2, 8, 15]
# b = [3, 6, 10, 18]

# if b[i] > a[i - 1]: 都删掉


class Solution:
    def merge(self, intervals):
        """
        :type intervals: List[Interval]
        :rtype: List[Interval]
        """
        ab = [[1, 3], [2, 6], [8, 10], [15, 18]]
        a = [1, 2, 8, 15]
        b = [3, 6, 10, 18]

        lista = []
        listb = []
        # listab = []

        aa = []
        bb = []
        for a, b in intervals:
            lista.append(a)
            listb.append(b)
            lista.sort()
            listb.sort()
        print(lista)
        print(listb)
        # listab.append(lista[0])
        aa.append(lista[0])
        for i in range(1, len(intervals)):
            if lista[i] > listb[i - 1]:
                # listab.append(listb[i - 1])
                # listab.append(lista[i])
                aa.append(lista[i])
                bb.append(listb[i - 1])
        bb.append(listb[len(intervals) - 1])
        # listab.append(listb[len(intervals) - 1])
        # print(listab)
        print(aa)
        print(bb)

        # print(zip(aa,bb))
        # print(list(zip(aa,bb)))
        endlist = []
        for i in zip(aa, bb):
            endlist.append(list(i))
        # print(endlist)
        return endlist


ab = [[1, 3], [2, 6], [8, 10], [15, 18]]
s = Solution()
endlist = s.merge(ab)
print(endlist)
